package com.example.androidmaze;


import android.util.Log;
import android.view.View;

import com.nick.robots.CuriousGamblerDriver;
import com.nick.robots.CuriousGamblerRobot;
import com.nick.robots.GamblerRobot;
import com.nick.robots.GamblerRobotDriver;
import com.nick.robots.Robot;
import com.nick.robots.RobotDriver;
import com.nick.robots.StandardRobot;
import com.nick.robots.WallFollowerDriver;
import com.nick.robots.WallFollowerRobot;
import com.nick.robots.WizardRobot;
import com.nick.robots.WizardRobotDriver;

public class Singleton {
	private Maze maze;
	Robot bot;
	GamblerRobot gamblerBot;
	WizardRobot wizardBot;
	CuriousGamblerRobot curiousBot;
	WallFollowerRobot wallFollowerBot;
	RobotDriver driver;
	
	private static Singleton mInstance = null;
 
    private Singleton(){
    	
    }
    
    public static Singleton getInstance(){
        if(mInstance == null)
        {
            mInstance = new Singleton();
        }
        return mInstance;
    }
 
    public Maze getMaze(){
        return this.maze;
    }
	
	public void setMaze(int algorithm, View view, int difficulty) {
		this.maze = new Maze(algorithm, view, difficulty);
		Log.v("Singleton", "setMaze(" + algorithm + ", " + view + ", " + difficulty+ ")");
		maze.init();
		Log.v("Singleton", "maze initialized");
	}
	
	public void setDriver(String strOperation)
	{
		if (maze != null)
		{
			bot = new StandardRobot(maze);
			Log.v("Singleton.java SetDriver Method", "Value of strOperation: "+strOperation);
			//Standard Robot used until otherwise needed
			//The case of manual is already handled in PLay Activity
			if (strOperation.equals("Manual"))
			{
//				driver = 
			}
			else if(strOperation.equals("Gambler"))
			{
				gamblerBot = new GamblerRobot(maze);
				driver = new GamblerRobotDriver(gamblerBot);
			}
			else if (strOperation.equals("Curious Gambler"))
			{
				curiousBot = new CuriousGamblerRobot(maze);
				driver = new CuriousGamblerDriver(curiousBot);
			}
			else if (strOperation.equals("Wall Follower"))
			{
				wallFollowerBot = new WallFollowerRobot(maze);
				driver = new WallFollowerDriver(wallFollowerBot);
			}
			else if(strOperation.equals("Wizard"))
			{
				wizardBot = new WizardRobot(maze);
				driver = new WizardRobotDriver(wizardBot);
			}
		}
		else
		{
			Log.v("Singleton Setting Driver and Bot", "Maze not initialized");
		}
	}
	
	public void startRobot()
	{
		try {
			driver.drive2Exit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
